﻿Imports Mysoft.Map.Service
Imports System.Text

Partial Public Class EventServiceTest
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        EventService.SubscribeEventGlobal()
        Me.txtLog.Text += "订阅成功" & System.Environment.NewLine
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
        Dim stationGUIDs As String = "2BA3F434-FC97-4928-A8F7-3C98A6C6EF12;67A69A71-BCB3-4A2C-B4D7-B176D8AFD5A2"
        Dim arrGUID() As String = {"a", "b", "c"}

        '触发删除岗位事件
        Dim arrResult As ArrayList = EventService.SyncRaiseEvent("删除岗位", arrGUID)

        Dim result As Hashtable = Mysoft.Map.Caching.MyCache.Get("事件")
        If Not result Is Nothing Then

            For Each de As DictionaryEntry In result
                Me.txtLog.Text += de.Value & System.Environment.NewLine
            Next
        End If

        '遍历多个事件处理程序的返回结果
        ' 1、如果此事件没有任何订阅者，则返回Nothing。
        ' 2、如果其中一个事件处理程序异常，返回值列表中依然包含该返回值，只是该返回值为Nothing。
        If Not arrResult Is Nothing Then
            Dim blnResult As Boolean = True
            For Each s As EventHandleState In arrResult
                If s Is Nothing OrElse Not s.State Then blnResult = False
            Next

            If Not blnResult Then
                Me.txtLog.Text += "删除岗位失败！" & System.Environment.NewLine
            Else
                Me.txtLog.Text += "删除岗位成功！" & System.Environment.NewLine
            End If
        Else
            Me.txtLog.Text += "删除岗位事件没有订阅者！" & System.Environment.NewLine
        End If


    End Sub

    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
        'EventService.UnSubscribeEventGlobal()
        'Me.txtLog.Text += "反订阅成功" & System.Environment.NewLine

    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click

    End Sub

    Protected Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click
        Dim loger As StringBuilder = CType(Mysoft.Map.Caching.MyCache.Get("事件日志"), StringBuilder)
        If Not loger Is Nothing Then
            Me.txtLog.Text = loger.ToString()
            Mysoft.Map.Caching.MyCache.Remove("事件日志")
        Else
            Me.txtLog.Text = "没有任何事件日志！"
        End If
    End Sub
End Class